#include "junix.h"

int main(int argc, char **argv)
{
	int fd=fileno(stdout);
	assert(fd==1);
	
	char *p="hello,World!\n";
	int len=strlen(p);
	if(	write(fd,p,len) != len)
		err_sys("write");

	FILE *fp=fdopen(STDOUT_FILENO,"w");
	if(fp==NULL)
		err_quit("fdopen error");

	if(fputs(p,fp)==EOF)
		err_quit("fputs error");

	clearerr(fp);

	printf("%s\n",__FILE__);
	if( (fp=fopen( __FILE__,"r"))==NULL)
		err_quit("freopen error");

	char buf[1024];
	while( fgets(buf,1024,fp) != NULL)
		if(fputs(buf,stdout) == EOF)
			err_quit("fputs error");

	if(ferror(fp))
		err_quit("ferror");

	fclose(fp);

	return 0;
}

